package com.dingding.service.activity.core.dao.impl;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.dingding.common.core.base.dao.impl.BaseDaoImpl;
import com.dingding.common.core.beans.AdvertiseStat;
import com.dingding.service.activity.core.dao.IAdvertiseStatDao;

/**
 * 
 * @ClassName: CityImpl 
 * @Description: 城市列表操作DAO实现
 * @author CHEHAUNBO 
 * @date 2016年2月3日 下午5:27:34
 * 
 */
@Component("advertiseStatDao")
public class AdvertiseStatDaoImpl extends BaseDaoImpl<AdvertiseStat> implements IAdvertiseStatDao {

	private Logger log = Logger.getLogger(this.getClass());

	/**
	 * @Title: addAdvertiseClickNum
	 * @Description: 增加推广公司相应的统计次数
	 * @param asId 推广公司的id 
	 * @param type 统计操作的类型（1：点击  2：分享  3：注册）
	 * @author fengshuonan
	 * @override
	 */
	public synchronized void addAdvertiseNum(String asId, int type) {

		AdvertiseStat advertiseStat = getById(asId);

		// 如果查询结果为空
		if (advertiseStat == null) {

			log.info("根据id获取推广公司信息出错！AdvertiseStatDaoImpl：addAdvertiseNum（）");
			return;
		}

		if (advertiseStat.getClickNum() == null) {
			advertiseStat.setClickNum(0);
		}

		if (advertiseStat.getRegNum() == null) {
			advertiseStat.setRegNum(0);
		}

		if (advertiseStat.getShareNum() == null) {
			advertiseStat.setShareNum(0);
		}

		switch (type) {

		case 1:
			advertiseStat.setClickNum(advertiseStat.getClickNum() + 1);
			break;
		case 2:
			advertiseStat.setShareNum(advertiseStat.getShareNum() + 1);
			break;
		case 3:
			advertiseStat.setRegNum(advertiseStat.getRegNum() + 1);
		}
	}

}
